Customer behaviour
analysis & churn prediction
By : Vertikal Willis
DS 19
www.presentationgo.com
Introduction
Datasets Introduction
Untuk final project kali ini, saya menggunakan datasets ‘Telco
Customer Churn’. Datasets ini bersumber dari Kaggle dan cukup
umum diketahui oleh kalangan praktisi data. Saya merombak
sedikit datasets ini dengan menghapus dan meng-edit beberapa
nilai dengan tujuan untuk mengotori data karena datasets
bawaan terlalu bersih dan rapih.
About Telco Company
Perusahaan telco ini adalah perusahaan yang bergerak sebagai
ISP (Internet Service Provider). Perusahaan ini menyediakan jasa
internet, telefon rumah dan berbagai produk-produk berbasis
teknologi seperti online security, device protection, streaming dll.
www.presentationgo.com
Problem Overview
So what’s wrong?
Masalah yang dihadapi oleh perusahaan adalah tingginya angka
customer yang churned. Pemilik perusahaan ingin mengetahui
penyebab mengapa tingginya angka customer churn dan
membuat suatu system prediksi apakah customer akan churn /
tidak dengan tujuan untuk dapat memprospek potential churned
customer sehingga dapat mengurangi kerugian.
www.presentationgo.com
Objective
Goals
Berdasarkan problem yang ada, maka tim data membuat 2 goals
utama yaitu :
1.Mencari informasi dan meaningful insights serta pattern-
pattern yang ada terkait churned customers.
2. Membuat ML model classifier yang reliable untuk mendeteksi
customer churned.
How
Bagaimana cara kami mencapai goals tersebut?
1.Melakukan banyak EDA untuk mencari insights dan pattern-
pattern maupun error/kesalahan dalam data.
2.Melakukan tuning dan komparasi beberapa model ML dengan
Teknik-Teknik yang cocok.
www.presentationgo.com
Workflow
DATA PREPARATION
Data preparation including import libraries,
handling missing values, outliers handling,
remove duplicate, data wrangling, feature
engineering and columns understanding
EDA
Standard EDA (descriptive statistic, univariate
analysis and multivariate analysis), deep-dive
EDA with rich interpretation and visualization
FEATURE ANALYSIS
Encoding columns, feature selection with
various techniques.
MODELLING
Create several ML model and compare them
based on reliable metrics.
01
02
03
04
6
RangeIndex
: 7043 entries, 0 to 7042
Column
Non-null Count Dtype
CustomerID
7043 non-null object
gender
7043 non-null object
SeniorCitizen
7043 non-null int64
Partner
7043 non-null object
Dependents
7043 non-null object
tenure
7043 non-null int64
PhoneService
7043 non-null object
MultipleLines
7043 non-null object
InternetService
7043 non-null object
OnlineSecurity
7043 non-null object
OnlineBackup
7043 non-null object
DeviceProtection
6627 non-null object
TechSupport
7043 non-null object
StreamingTV
7043 non-null object
StreamingMovies
7043 non-null object
Contract
6798 non-null object
PaperlessBilling
7043 non-null object
PaymentMethod
7043 non-null object
MonthlyCharges
7043 non-null float64
TotalCharges
4859 non-null object
Churn
7043 non-null object
Hobby
4201 non-null object
Missing value Handling
3.48 %
31.0 %
5.91 %
40.3 %
Univariate imputation by
proportion
Univariate imputation by
proportion
Multivariate imputation by
MonthlyCharges x tenure
Delete column
7
Data checking
Karena nilai TotalCharges adalah +- MonthlyCharges * Tenure, maka kita bisa memfilter &
delete baris yang invalid
Index
RealTC
CustomTC
Difference (%)
0
29.85
4029.75
13400.0
5
820.50
11958.00
1357.0
18
528.35
4692.00
788.0
19
1862.90
8014.45
330.0
3
1840.75
5773.20
214.0
128
74.56
19.75
74.0
47
589.00
161.30
73.0
.…
…
.
….
…
.
Saya akan menghapus rows
yang memiliki difference TC
>40%
8
Feature engineering
Disini saya akan melakukan feature creation baru yaitu :
1.Services PhoneService & InternetService
2.TotalBenefits Sum of benefits
Tujuannya adalah untuk memudahkan analisa.
9
Outliers handling
Outliers in tenure will be
deleted
10
Exploratory Data Analysis
Fiber optic memiliki churned rate 2x dari DSL
Phone only memiliki churned rate yang sangat
rendah ( +- 7% )
Mayoritas customer didominasi oleh customer
single tetap churn probabilitynya juga
merupakan yang tertinggi
11
Jumlah benefit rata-rata yang diambil
customer adalah 1 –3 benefits dengan benefit
streaming yang terbanyak
Exploratory Data Analysis
12
Fiber optic jauh lebih
mahal dari DSL
Fitur hiburan lebih mahal
dari fitur proteksi
Menggunakan phone
service dengan multiple
line dikenakan biaya cas
+- 5 USD lebih mahal
Exploratory Data Analysis
13
Jumlah customer pada
segment MC 70 –100 adalah
yang tertinggi namun churn
probabilitynya pada segment
ini juga merupakan yang
tertinggi!
Exploratory Data Analysis
14
Here’s some interesting insights :
1. Churned customer lebih tersebar pada
tenure rendah khususnya pada MC 70 –
100 USD (green area)
2. Pada rentan harga 20 –25 USD, churned
customer jumlahnya sangat jauh lebih
sedikit dari customer yang tidak churn.
Customer pada rentan harga ini
didominasi oleh customer pemakai
‘phone only’
3. Blue area = Dominated by Non-churned
customer
4. Green area = Dominated by churned
customer
Exploratory Data Analysis
15
Here’s some interesting insights :
1. Customer baru cenderung lebih memilih
kontrak Month-to-Month sedangkan
Customer lama lebih ke kontrak tahunan.
2. Berdasarkan area biru dan hijau,
customer dengan kontrak Month-to-
Month lebih cenderung churned.
3. Ini juga berlaku pada customer pengguna
‘phone only’ dimana kebanyakan juga
menggunakan kontrak tahunan.
Kesimpulan:
1. Customer baru masih memiliki keraguan
terhadap produk dan memilih kontrak bulanan
dari pada tahunan. Jika dalam beberapa
waktu, mereka merasa puas maka mereka
akan upgrade ke kontrak tahunan dan tidak
churn.
Exploratory Data Analysis
16
Here’s some interesting insights :
1. Pada area hijau (churned customer)
didominasi oleh pengguna internet Fiber
optic dan jumlah totalbenefits yang
sedikit.
2. Pada area biru (non-churned customer)
didominasi oleh pengguna internet DSL
dan jumlah totalbenefits yang lebih
banyak
What does it mean?:
1. Pada rentan harga ini, customers dihadapkan
2 opsi produk yaitu menggunakan internet
fiber optic dengan jumlah benefit yang lebih
sedikit atau menggunakan internet DSL yang
lebih murah namun jumlah benefit yang
diambil lebih banyak. Customer lebih
menyukai opsi kedua.
Exploratory Data Analysis
17
1. Phone product sangat dicintai oleh customer.
2. New customer memiliki keraguan sehingga
memilih kontrak bulanan dan lebih berpotensi
churn dari pada kontrak tahunan.
3. Fiber optic is too expensive & overrated! Dengan
uang yang sama customer bisa mendapatkan paket
DSL + 3-4 benefits
4. Overall, customer lebih cenderung mengambil
jumlah benefit yang sedikit ( < 4 )
1. ‘If it ain’t broke, don’t fix it’. Jangan menyetuh
produk phone service karena sudah bagus.
2. Berikan promo dan keuntungan yang lebih pada
kontrak tahunan daripada bulanan.
3. Kaji ulang biaya fiber optic (disarankan untuk
dikurangi)
4. Berikan promo paket bundling beberapa benefits
sekaligus eg. Free netflix 6 month for 6 subscribed
benefits.
Exploratory Data Analysis
18
Modelling Preparation
3Important things to know before modelling :
Datasets is Imbalanced
Types and cost of errors
By default, ML models are
designed for balanced datasets
and treating negative and
positive class equally
19
There are 3 types of errors:
Detect non-churned
customer as churned (FP) 1
Detect churned customer
as non-churned on regular
customers (<95 MC)
(FN1) 3
Detect churned customer
as non-churned on VIP
customers (>95 MC)
(FN2) 5
Miss-classification cost
Modelling Preparation
20
Based on the problem, here’s some thing we can do:
Hyperparameter tuning Selecting best parameter
for model
Decision threshold tuning Default is 0,5 and usually not
optimal on this problem
SMOTE Oversampling technique
Modified loss function Inference model loss
function by inserting weight
using sample_weight param.
Modelling Preparation
21
Models : Random Forest, XG Boost, Logistic Regression
Combination :
1. Hyperparameter tuning + threshold tuning
2. Hyperparameter tuning + SMOTE + threshold tuning
3. Hyperparameter tuning + custom loss function + threshold
tuning
Evaluation metrics :
1. Custom scoring (based on FP +FN1 + FN2) for comparing models
2. Precision, recall & f1-score for comparing models and to determine if the models
are good enough or not
Modelling Preparation
22
Feature Selection
1. Remove multicollinearity feature : TotalCharges 2. Remove PaymentMethod because it’s irrelevant
3. Feature selection using feature of importance of
Random Forest Clasiffier (wrapper)
-. Contract
-. Tenure
-. Internet Service Fiber optic
-. MonthlyCharges
-. Internet Service_No
-. Churn
www.presentationgo.com
Data split
Split data into train and test.
Train data will automatically
divided into validation in
GridSearchCV.
HyperParameter
Tuning
GridSearchCV (cv=5) use
custom scoring to find the
best model parameter +
threshold.
Train on test data
Train on test data using the
best parameter and threshold
produced by GridSearchCV.
Evaluation
Evaluate the model on test
data with custom loss_score,
precision, recall and f1-score.
Modelling
www.presentationgo.com
Your Footer Here 24
Modelling
Evaluation Table
Combination
Model
Threshold
Precision
Recall
F1_score
Combination1
LG
0,2
0,463158
0.853186
0.60039
Combination1
XG
0,2
0,459581
0.850416
0.596696
Combination3
LG
0,5
0,466154
0.839335
0.599407
Combination3
XG
0,5
0,467391
0.833795
0.599005
Combination2
XG
0,5
0,506329
0.775623
0.612691
Combination2
LG
0,5
0,475806
0.817175
0.601427
Combination3
RF
0,5
0,460123
0.831025
0.5923
Combination2
RF
0,4
0,446064
0.847645
0.584527
Combination1
RF
0,2
0,440922
0.847645
0.580095
The best model is Logistic Regression on Combination1
(Hyperparameter tuning + threshold tuning) with parameter :
-. ‘C’ :10.0
-. ‘max_iter’ :100
-. ‘penalty’ : l2
-. ‘solver’ : liblinear.
With precision 46%, recall 85%and f1 score 60%, I consider
this model not great not terrible, just OK.
www.presentationgo.com
Your Footer Here 25
Modelling
1233
530 57%
Note : From business perspective, It is very
important to consider the cost of prospecting a
potential churned customer with the
effectiveness of the method used in prospecting.
If the number is very low than it is useless
building this ML model.
Losses score
By applying ML, we can reduce
losses up to 57%(if 100% succeed in
prevent potential churned customer)
www.presentationgo.com
Thank You!
Your Footer Here 26
Vertikal Willis
DS 19